using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows;
using System.Windows.Markup;

namespace Hearthbuddy.Windows
{
	/// <summary>
	/// Interaction logic for Downloading.xaml
	/// </summary>
	/// <summary>
	/// DownloadingWindow
	/// </summary>
	public partial class DownloadingWindow : Window, IComponentConnector
	{
		private readonly string string_0;

		private readonly string string_1;

		internal DownloadingWindow downloadingWindow_0;

		private bool bool_0;

		public DownloadingWindow(string filter, string exePath)
		{
			string_0 = exePath;
			string_1 = filter;
			InitializeComponent();
		}

		private void downloadingWindow_0_Loaded(object sender, RoutedEventArgs e)
		{
			ThreadPool.QueueUserWorkItem(delegate
			{
				WebClient webClient = new WebClient();
				try
				{
					webClient.DownloadFile("http://updates.buddyauth.com/NewUpdater.exe", string_0);
					if (!File.Exists(string_0))
					{
						MessageBox.Show("The Buddyupdater could not be executed. Please update manually. The program will now exit.", "Hearthbuddy", MessageBoxButton.OK, MessageBoxImage.Hand);
						Environment.Exit(0);
					}
					Process.Start(string_0, string_1 + " \"" + Assembly.GetEntryAssembly().Location + "\"");
					Environment.Exit(0);
				}
				catch (Exception)
				{
					MessageBox.Show("The Buddyupdater could not be executed. Please update manually. The program will now exit.", "Hearthbuddy", MessageBoxButton.OK, MessageBoxImage.Hand);
					Environment.Exit(0);
				}
			});
		}
		/*
		/// <summary>
		/// InitializeComponent
		/// </summary>
		[DebuggerNonUserCode]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		public void InitializeComponent()
		{
			if (!bool_0)
			{
				bool_0 = true;
				Uri resourceLocator = new Uri("/Hearthbuddy;component/windows/downloadingwindow.xaml", UriKind.Relative);
				Application.LoadComponent(this, resourceLocator);
			}
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		[DebuggerNonUserCode]
		void IComponentConnector.Connect(int connectionId, object target)
		{
			if (connectionId == 1)
			{
				downloadingWindow_0 = (DownloadingWindow)target;
				downloadingWindow_0.Loaded += downloadingWindow_0_Loaded;
			}
			else
			{
				bool_0 = true;
			}
		}*/

		[CompilerGenerated]
		private void method_0(object object_0)
		{
			WebClient webClient = new WebClient();
			try
			{
				webClient.DownloadFile("http://updates.buddyauth.com/NewUpdater.exe", string_0);
				if (!File.Exists(string_0))
				{
					MessageBox.Show("The Buddyupdater could not be executed. Please update manually. The program will now exit.", "Hearthbuddy", MessageBoxButton.OK, MessageBoxImage.Hand);
					Environment.Exit(0);
				}
				Process.Start(string_0, string_1 + " \"" + Assembly.GetEntryAssembly().Location + "\"");
				Environment.Exit(0);
			}
			catch (Exception)
			{
				MessageBox.Show("The Buddyupdater could not be executed. Please update manually. The program will now exit.", "Hearthbuddy", MessageBoxButton.OK, MessageBoxImage.Hand);
				Environment.Exit(0);
			}
		}
	}
}
